home *** CD-ROM | disk | FTP | other *** search
/ WINMX Assorted Textfiles / Ebooks.tar / Text - Tech - Hacking - Hacking Unix - Part 4.txt < prev    next >
Text File  |  2003-09-27  |  30KB  |  776 lines

  1.                           - HACKING UNIX -
  2.                              PART FOUR:
  3.  
  4.                         Dealing with Firewalls
  5.                  -----------------------------------
  6.  
  7. Edit started on 05/06/02 (MM-DD-YY)
  8. Edit finished on 01/07/02 (MM-DD-YY)
  9. By: detach (XT) - [DuHo] <http://www.duho.org>
  10.  
  11.  
  12. &       ** This is a multi-part tutorial,
  13. &       ** please check our website for other
  14. &       ** parts:
  15. &       ** http://www.duho.org/
  16. &
  17.  
  18. INDEX:
  19.  
  20. 0. - Forword
  21. 1. - Introduction
  22. 2. - Packet Filtering Firewalls
  23.      2.1 - A pracical Example
  24. 3. - How does the packet filter work
  25.      3.1 - Introduction
  26.      3.2 - Stateless or Stateful
  27. 4. - Dealing with Firewalls
  28.      4.1 - Introduction
  29.      4.2 - 2D mapping of a firewall ruleset
  30.      4.3 - 3D mapping of a firewall ruleset
  31. 5. - Using the gathered information
  32. 6. - Final words
  33.  
  34. 0. Forword
  35.  
  36. This part explains what firewalls are, their purpose and how they work.
  37. You will learn several techniques to detect a firewall and to discover
  38. it's ruleset later on in this part. Understanding firewalls requires
  39. understanding on networking and other things, certain references are
  40. included to obtain that knowledge.
  41. It's important to understand the role of firewalls in security and how 
  42. they work. This will be described and later on I'll focus on common 
  43. weaknesses.
  44.  
  45. 1. - Introduction
  46.  
  47. Users on an internal network may need to access other networks in an 
  48. interconnected environment.
  49. An organisation may want to restrict access to the Internet and will 
  50. especially want to restrict access from the untrusted Internet into the 
  51. internal network.
  52. Firewalls are used to control network activity between the interconnected 
  53. networks.
  54.  
  55. Therefor an administrator creates a policy based on information about the 
  56. services that users need to access on the external network and the 
  57. services on the internal network requiring access from the outside of the 
  58. network.
  59. It is also possible to restrict access into the internal network to a 
  60. certain part of the external network and vise-versa.
  61.  
  62. Using the policy, the ruleset is defined and applied to a firewall placed
  63. between the two networks. A firewall is only effective if users are forced
  64. to access the external network through the firewall (and vise-versa).
  65. When a computer on the internal network has a modem it may be possible to
  66. access the external network through a dial-up connection completely
  67. bypassing the policy.
  68.  
  69. In this part you'll be introduced to the techniques hackers use to deal 
  70. with firewalls.
  71.  
  72. 2. Packet Filtering Firewalls
  73.  
  74. In this chapter I discuss where and how firewalls are used. Chapter 3
  75. generally explains how a firewall works and later on we'll focus on
  76. ``dealing with packet filters''.
  77.  
  78. Packet filters have a ruleset defined by the administrator. The packet
  79. filter often operates at kernel-level and checks the header* on the packet
  80. to see where it's heading. It than looks for these targets in it's ruleset
  81. and decides it's fait. The packet can be discarded or accepted in
  82. different ways, or it may trigger another action (for example to accept
  83. the packet to pass through but to log the event).
  84. {
  85.     A header is like an envelope that sets the receiver (and sender).
  86.     On network-packets we have multiple envelopes (headers) that 
  87.     together form the exact destination (it is layered).
  88. }
  89.  
  90. In the case of the internet most packet filters operate on IP and TCP 
  91. level. IP specifies the host the packet is heading to, TCP identifies the 
  92. program that the packet is destined for.
  93.  
  94. 2.1 A practical example.
  95.  
  96. We'll follow the proces the administrator of TotallySecure Inc. takes 
  97. for defining a packet filtering ruleset.
  98.  
  99. The first smart rule the administrator defines looks like this:
  100.  
  101. Source: Anywhere
  102. Destination: Anywhere
  103. Protocol: Any
  104. Destination port: Any
  105. Policy: DENY
  106.  
  107. The next thing the administrator does is to identify the exceptions to 
  108. this base rule.
  109. {
  110.     Note that there are also administrators that at first ACCEPT 
  111.     everything and then close some ports. This is the wrong way of 
  112.     thinking.
  113.     Security can only be brought to the max. when you first disable 
  114.     everything and then enable some required features. And that goes 
  115.     for almost any element of a system.
  116. }
  117.  
  118. An administrator may have a mailserver inside the organisations network. 
  119. The mail is delivered from and to the mailserver through the SMTP service 
  120. (for example sendmail or qmail). The administrator knows that the SMTP 
  121. service must be reachable from the internet to be able to receive mail.
  122.  
  123. So the administrator defines a new rule (exception on the first rule):
  124.  
  125. Source: External (Internet)
  126. Destination: Internal mailhost
  127. Protocol: TCP
  128. Destination Port: 25 (SMTP)
  129. Policy: ACCEPT.
  130.  
  131. Meaning that any packets from any address destined for the SMTP service 
  132. (TCP port 25) on the mailhost will be forwarded to the appropriate 
  133. direction.
  134.  
  135. The administrator grants all systems on the internet to deliver e-mail to 
  136. users' mailboxes. He does not have to define a rule for the internal 
  137. network. The users just need to connect to the mailserver, not to a 
  138. mailserver outside the internal network, so he'll only need to make an 
  139. exception for SMTP from the mailhost:
  140.  
  141. Source: Internal mailhost
  142. Destination: External (Internet)
  143. Protocol: TCP
  144. Port: 25
  145. Policy: ACCEPT.
  146.  
  147. The next thing the administrator wants is to allow users to receive their 
  148. mail from their mailbox on the mailserver using the POP3 protocol. The 
  149. administrator prefers to DENY access to the POP3 service from the internet 
  150. side. He asks several users if they *have to* retrieve their mail from 
  151. anywhere outside the organisation and finds out it's safe to block access 
  152. to this server from the internet-side for POP3 access.
  153.  
  154. He knows he won't need to change the firewall rules as this is no 
  155. exception to the first rule, although he just adds it to his note for 
  156. reference:
  157.  
  158. Source: External
  159. Destination: Internal
  160. Protocol: TCP
  161. Destination Port: 110 (POP3)
  162. Policy: DENY.
  163.  
  164. The administrator realises the simple fact that users need to use HTTP 
  165. access to the internet. He can simply ACCEPT outgoing HTTP traffic or 
  166. further restrict this access using a proxy server (in the last case he 
  167. only needs to allow outgoing HTTP from the proxy server).
  168.  
  169. He decides the last method is more secure. He installs a HTTP/HTTPS/FTP
  170. proxy all-in-one solution. The proxy server runs on port 8080 and needs
  171. only to be accessed from the internal network. So incoming traffic to port
  172. 8080 can safely be blocked. He sets up a LAN for the users behind the 
  173. proxy server. He adds a second network card to the mailserver so that the 
  174. mailserver is accessible on the LAN aswell as from the internet.
  175.  
  176. The first rule he adds is to allow outgoing FTP/HTTP/HTTPS from the 
  177. proxyserver:
  178.  
  179. Source: Internal proxy-server
  180. Destination: External
  181. Protocol: TCP
  182. Destination Port: 21 (FTP), 80 (HTTP), 443 (HTTPS)
  183. Policy: ACCEPT.
  184.  
  185. The administrator has now defined all rules he thinks are necessary. Next 
  186. the administrator goes on with adding spam- and virusblocking to his 
  187. mailserver etcetera.
  188.  
  189. 3. How does the packet filter work.
  190.  
  191. 3.1 Introduction
  192.  
  193. Network packets come into the network card which are then received at the
  194. kernel of the operating system. If the operating system is setup as a
  195. router it reads the packet and knows where to send the packet to. When a
  196. firewall is installed it has the ability to read the packets and the
  197. possibility to do something with it. It can drop (discard) the packet,
  198. refuse (block, reject) the packet, accept the packet for further
  199. processing or manipulate (mangle) the packet. All these decisions are
  200. based on the information in the protocol's header which are matched
  201. against filter rules.
  202.  
  203. I haven't explained the difference between dropping a packet and refusing
  204. (blocking) a packet. A dropped packet is simply thrown away (discarded)  
  205. and the sender of that packet receives no notice. Rejecting (refusing) a
  206. packet means discarding the packet and replying with a TCP RST packet, 
  207. the same response as it gets when you would try to open a connection to a 
  208. non-existing port. Ofcourse this rejecting only takes place when there are 
  209. specific flags set. To fully understand this you should read RFC 793 (TCP) 
  210. and RFC 791 (IP).
  211.  
  212. 3.2 Stateless or Stateful.
  213.  
  214. A stateless firewall is very basic, it may simply check destination and 
  215. source address, destination port and source port and decide what to do 
  216. with it.
  217.  
  218. A stateful packet filter keeps track of a connection and has the ability 
  219. to do some meaningful packet manipulation. For example Network Address 
  220. Translation (NAT), where protocol information can be changed before it is 
  221. forwarded. This is used for example to make an internal host 
  222. (with a private-range IP-address) addressable from the internet.
  223.  
  224. Stateful packet filters can also have protocol helpers, which can be used 
  225. to make a protocol work through a firewall by manipulating the 
  226. application-level-data that the packet contains or anything more creative.
  227.  
  228. 4. Dealing with Firewalls.
  229.  
  230. 4.1 Introduction
  231.  
  232. Firewalls itself are not a target for our attacks. This may sound obvious
  233. but this is exactly what is suggested when saying ``how can I break
  234. security?'' or more explicitly ``how can I break through a firewall''. It
  235. is not about breaking security it is about taking advantage of insecurity
  236. elsewhere. More intelligent people do know this but still talk about
  237. 'breaking security' which is plain wrong. That's why I called this part
  238. "Dealing with Firewalls" and not "Breaking Firewalls".
  239. Although, there have been occasions where the firewall software itself
  240. introduced new vulnerabilities. And some (older) firewalls may simply not 
  241. work well, but you'll see that. At first we will concentrate on a 
  242. different way to get around firewall restrictions anyway.
  243.  
  244. So we are going to *deal* with the firewalls and we will find out a
  245. different way to defeat or bypass them.
  246.  
  247. 4.2 2D discovery of a firewall ruleset
  248.  
  249. In this paragraph I will explain some techniques useful to map a firewalls 
  250. ruleset. This information is very useful for later stages of attack. For 
  251. example, you will already know how your backdoor needs to be configured, 
  252. or what kind of backdoor you will need. You may also need the information 
  253. for some kid of attacks on systems behind the firewall. We are not going 
  254. to focus on compromising the firewall initially because it is probably 
  255. secure enough, however, if it is vulnerable to remote attack we'll find 
  256. out anyway.
  257.  
  258. Now we are going to watch over the shoulder of a hacker named John that is
  259. about to map the firewall ruleset of TotallySecure Inc's firewall. John 
  260. has just surfed into the website of TotallySecure and wants to know
  261. if the company deserves the name it has. Note that this stage should be
  262. part of the information gathering stage discussed in part 2.
  263.  
  264. John first sends a harmless ping addressed to the webserver:
  265.  
  266. # ping www.totallysecure.org
  267. PING www.totallysecure.org (123.123.123.123): 56 octets data
  268.  
  269. --- www.totallysecure.org ping statistics ---
  270. 12 packets transmitted, 0 packets received, 100% packet loss
  271. #
  272.  
  273. John knows there must be a some device in the way that drops the ICMP
  274. (ping)  ECHO REQUEST packets, although he knows it doesn't have to be the
  275. webserver itself.
  276.  
  277. Next, John wants to know if some ports are also being filtered (dropping
  278. incoming connections on certain ports). Administrators often rather filter
  279. ports and protocols instead of blocking them because the host appears to
  280. be offline.
  281. With the knowledge that a closed port needs to respond with an RST/ACK 
  282. packet when sending a SYN packet to it, he could see if the firewall is 
  283. filtering ports. He'll use the program 'hping' to discover this (found at 
  284. http://www.hping.org/):
  285.  
  286. # hping www.totallysecure.org -S -p 85
  287. HPING www.totallysecure.org (eth0 123.123.123.123): S set, 40 headers + 0 data bytes
  288.  
  289. --- www.totallysecure.org hping statistic ---
  290. 10 packets transmitted, 0 packets received, 100% packet loss
  291. round-trip min/avg/max = 0.0/0.0/0.0 ms
  292. #
  293.  
  294. The -S switch indicates the SYN flag to be set and the -p flag specifies 
  295. the destination port. No response at all, it must be filtered too. Now, if 
  296. this firewall is intelligent in anyway, it will also drop any loose ACK 
  297. packets to that port. The normal behavior when sending a lonesome ACK 
  298. packet to a port is to receive an RST response. Now if the firewall is not 
  299. that smart it may only block SYN (for connection synchronization) packets 
  300. to that port. If we receive an RST packet after sending an ACK packet to 
  301. port 85 it indicates that it's a very basic firewall.
  302.  
  303. # hping www.totallysecure.org -A -p 85
  304. HPING www.totallysecure.org (eth0 123.123.123.123): A set, 40 headers + 0 data bytes
  305.  
  306. --- www.totallysecure.org hping statistic ---
  307. 4 packets transmitted, 0 packets received, 100% packet loss
  308. round-trip min/avg/max = 0.0/0.0/0.0 ms
  309. #
  310.  
  311. No response at all, okay it's probably filtered properly. Note that the 
  312. ACK packets send to unfiltered ports (whether open or closed) always 
  313. return an RST packet. You can not determine if a port is open or closed.
  314.  
  315. Now, it is not important which port we used for this action (85), aslong 
  316. as we think it is probably not in use. It is this clue that may make us 
  317. think that the host has filtered all ports and made exceptions to specific 
  318. ports that require to be open (like the webserver). Atleast we may 
  319. conclude that because it is very unlikely port 85 is in use, as no 
  320. well-known service has this port assigned as yet.
  321. How do I know this?
  322.  
  323. # grep 85 /etc/services
  324. #
  325.  
  326. So if the admin is filtering a port that isn't in use, why wouldn't he 
  327. filter all ports that aren't in use? So John may assume now that the 
  328. administrators first rule was to DROP any connection on incoming ports, 
  329. atleast from the outside (the Internet). No ordinary backdoor could be 
  330. installed on the firewall without changing the ruleset if the firewall 
  331. works properly. Knowing that this packet filter also filters ACK packets, 
  332. we can later on scan all ports with ACK packets to make sure everything is 
  333. filtered.
  334.  
  335. There is another a way to see if the firewall is filtering properly, this
  336. is done by testing it with fragmented packets. Fragmented packets are
  337. normally used to send packets over networks with a low Maximum
  338. Transmission Unit (MTU). Fragments can be this small that even the header
  339. is split up into multiple packets. Some firewalls fail at blocking such
  340. packets as they don't have the complete header, and they don't wait to
  341. collect all fragments for reconstruction.
  342.  
  343. John performs a simple test against www.totallysecure.org with Fyodor's
  344. Nmap tool:
  345.  
  346. # nmap -sS -p85 -f www.totallysecure.org -P0
  347.  
  348. Starting nmap V. 2.54BETA30 ( www.insecure.org/nmap/ )
  349. Interesting ports on www.totallysecure.org (123.123.123.123):
  350. Port       State       Service
  351. 85/tcp     filtered    unknown
  352.  
  353. Nmap run completed -- 1 IP address (1 host up) scanned in 36 seconds
  354. #
  355.  
  356. He uses the -f switch to fragment the packet, -P0 to tell Nmap not to 
  357. check if the host is up (as PINGs don't pass through, Nmap will otherwise 
  358. think the host is down), -sS to do a SYN scan. As it turned out, Nmap 
  359. split the packet in 6 fragments, as seen with a header sniffer. We could 
  360. do this scan with ACK packets as well.
  361.  
  362. What if we send packets with no flags at all? A so-called NULL scan should 
  363. return RST packets if the port is closed, and no result if the port is 
  364. open. It is this why this scan is not really reliable, because this type 
  365. of scan indicates a port being open if it is filtered (dropped).
  366.  
  367. The problem is that Windows systems return an RST packet even if the port
  368. is open (against the specification) and so this scan is not usable to scan
  369. Windows systems. But it is still useful against Windows systems for
  370. testing the firewall ruleset, the same way as using ACK packets.
  371.  
  372. For UNIX systems it is useful if we have to deal with a basic firewall 
  373. that only blocks SYN packets. Because then we already know what port the 
  374. firewall is supposed to filter. Then we use a ACK scan to determine if the 
  375. firewall is a basic one. Then we use the NULL scan to see if the port 
  376. being filtered is actually open or not. For example:
  377.  
  378. Step 1:
  379.  
  380. # nmap -sS -p110 www.totallysecure.org -P0
  381.  
  382. Starting nmap V. 2.54BETA30 ( www.insecure.org/nmap/ )
  383. Interesting ports on www.totallysecure.org (123.123.123.123):
  384. Port       State       Service
  385. 110/tcp     filtered    pop3
  386.  
  387. Nmap run completed -- 1 IP address (1 host up) scanned in 1 second
  388. #
  389.  
  390. Step 2:
  391.  
  392. # nmap -sA -p110 www.totallysecure.org -P0
  393.  
  394. Starting nmap V. 2.54BETA30 ( www.insecure.org/nmap/ )
  395. The 1 scanned port on www.totallysecure.org (123.123.123.123) is: UNfiltered
  396.  
  397. Nmap run completed -- 1 IP address (1 host up) scanned in 1 second
  398. #
  399.  
  400. Step 3:
  401.  
  402. # nmap -sN -p80 www.totallysecure.org -P0
  403.  
  404. Starting nmap V. 2.54BETA30 ( www.insecure.org/nmap/ )
  405. Interesting ports on www.totallysecure.org (123.123.123.123):
  406. Port       State       Service
  407. 110/tcp     open        pop3
  408.  
  409.  
  410. Nmap run completed -- 1 IP address (1 host up) scanned in 12 seconds
  411. #
  412.  
  413. See, in case the admin used a basic packetfilter, we just found out the 
  414. POP3 service is open but filtered. If that didn't succeed, we should also 
  415. try in conjunction with the fragmentation option (-f). This knowledge may 
  416. introduce the idea that the port must somehow be in use, maybe only to 
  417. serve internal netwerk users. Otherwise the administrators is to lazy to 
  418. turn off the POP3 service.
  419.  
  420. Using the above techniques, John has a basic idea of the type of firewall
  421. being used. In this case John concludes www.totallysecure.org is secured
  422. by one or more firewalls that drop incoming connections on filtered ports.
  423. The firewall is not vulnerable to fragmented packets nor is it a basic
  424. firewall that chases after SYN packets only. John continues finishing his
  425. 2D view of the webserver by doing the SYN, ACK and NULL scans against all
  426. the 65535 possible ports during the period of about month (not not raise
  427. too much suspicion).
  428.  
  429. The 2D map results in:
  430.  
  431. Protocol ICMP: dropped
  432. All TCP ports dropped except port 80.
  433.  
  434. John has both gathered information on the open/closed ports and the 
  435. firewall configuration. He did it in a non-intrusive and stealthy manner.
  436.  
  437. The next questions John wants to investigate are:
  438.  
  439. - is the firewall on the same site as the webserver?
  440. - howmany firewalls are there?
  441. - where are the firewalls located?
  442.  
  443. This is what I call a 3D mapping. A 2D mapping maps all obstacles in the 
  444. way to a target, no knowledge of distance are known. In a 3D map John 
  445. knows on which systems services are available and where packets are 
  446. filtered.
  447.  
  448. 4.3 3D mapping of a firewall ruleset
  449.  
  450. What I call -3D mappings- are a series of probes and information gathering
  451. methods that result a visual map. It is used to determine which sites
  452. provide which services while figuring out why it is setup that way along
  453. with the location of where packets are filtered. Combining this
  454. information with the 2D mapping results a detailed report of the physical
  455. configuration as well the logical configuration and why it works that way.
  456.  
  457. Again, we'll follow John the hacker in his info gathering stage with 
  458. TotallySecure Inc. being his target.
  459.  
  460. In the 2D mapping stage John learned that (probably all) ICMP type packets 
  461. don't pass through. In this stage John wants to know which device along 
  462. the way is blocking it. Now how does he do that? He's about to use a 
  463. series of traceroute-type probes to determine the site that's blocking 
  464. these packets. First things firts, John writes a quick shell script for 
  465. determining the location of the ICMP filter:
  466.  
  467. --- trace_icmp.sh ---
  468. #!/bin/sh
  469. # determine ICMP filter location
  470.  
  471. cnt=1
  472. while [ $1 ] ; do
  473.    echo hop \#$cnt:
  474.    hping -1 -c 1 -t $cnt $1
  475.    let cnt=cnt+1
  476.    sleep 1
  477. done
  478. --- end ---
  479.  
  480. John is now able to determine where the packet is filtered.
  481.  
  482. --- determine ip address ---
  483.  
  484. # nslookup www.totallysecure.org
  485. Server:         127.0.0.1
  486. Address:        127.0.0.1#53
  487.  
  488. Name:   www.totallysecure.org
  489. Address: 123.123.123.123
  490.  
  491. #
  492.  
  493. --- end ---
  494.  
  495. John first looks up the ip adress so hping won't have to look it up itself 
  496. everytime.
  497.  
  498. --- trace icmp filter ---
  499.  
  500. bash-2.05a# ./trace_icmp.sh 123.123.123.123
  501. hop #1:
  502. HPING 123.123.123.123 (eth0 123.123.123.123): icmp mode set, 28 headers + 0 data bytes
  503. TTL 0 during transit from ip=100.100.100.1 name=gateway.attackers.org
  504.  
  505. --- 123.123.123.123 hping statistic ---
  506. 1 packets tramitted, 0 packets received, 100% packet loss
  507. round-trip min/avg/max = 0.0/0.0/0.0 ms
  508. hop #2:
  509. HPING 123.123.123.123 (eth0 123.123.123.123): icmp mode set, 28 headers + 0 data bytes
  510. TTL 0 during transit from ip=100.100.1.1 name=gateway.hackerisp.org
  511.  
  512. --- 123.123.123.123 hping statistic ---
  513. 1 packets tramitted, 0 packets received, 100% packet loss
  514. round-trip min/avg/max = 0.0/0.0/0.0 ms
  515.  
  516. ....
  517. ....
  518. ....
  519. ....
  520.  
  521. hop #18:
  522. HPING 123.123.123.123 (eth0 123.123.123.123): icmp mode set, 28 headers + 0 data bytes
  523.  
  524. --- 123.123.123.123 hping statistic ---
  525. 1 packets tramitted, 0 packets received, 100% packet loss
  526. round-trip min/avg/max = 0.0/0.0/0.0 ms
  527. hop #19:
  528. HPING 123.123.123.123 (eth0 123.123.123.123): icmp mode set, 28 headers + 0 data bytes
  529. ICMP Packet filtered from ip=123.123.1.1 name=UNKNOWN
  530.  
  531. --- end ---
  532.  
  533. Now this makes sense, the filter that filtered the ping packets was not 
  534. the one on the webserver... but a gateway at hop #19.
  535. Next John wants to know on which hop the webserver is. How does he figure 
  536. that out? Simple:
  537.  
  538. --- trace_tcp.sh ---
  539. #!/bin/sh
  540.  
  541. cnt=1
  542. while [ $1 ] ; do
  543.    echo hop \#$cnt:
  544.    hping -S -p $2 -c 1 -t $cnt $1
  545.    let cnt=cnt+1
  546.    sleep 1
  547. done
  548.  
  549. --- end ---
  550.  
  551. How could you use this script? Well, just pick a port that you know is 
  552. open, John will use port 80. Then this script can be used to determine the 
  553. number of hops until the port 80 has been reached.
  554.  
  555. Let's see John in the act:
  556.  
  557. --- trace count hops to destination ---
  558.  
  559. bash-2.05a# ./trace_tcp.sh 123.123.123.123 80
  560. hop #1:
  561. HPING 123.123.123.123 (eth0 123.123.123.123): S set, 40 headers + 0 data bytes
  562. TTL 0 during transit from ip=100.100.100.1 
  563. --- 123.123.123.123 hping statistic ---
  564. 1 packets tramitted, 0 packets received, 100% packet loss
  565. round-trip min/avg/max = 0.0/0.0/0.0 ms
  566.  
  567. ....
  568. ....
  569. ....
  570. ....
  571.  
  572. hop #21:
  573. HPING 123.123.123.123 (eth0 123.123.123.123): S set, 40 headers + 0 data bytes
  574. len=46 ip=123.123.123.123 flags=SA DF seq=0 ttl=63 id=0 win=5840 rtt=575.6 ms
  575.  
  576. --- end ---
  577.  
  578. John learned that there is a packet filter filtering ICMP packets at hop
  579. 19, and the webserver is at hop 21. That's interesting, so the second
  580. gateway from the webserver is filtering ICMP packets. It may also be
  581. possible that the first gateway before the webserver is also filtering
  582. ICMP, but that doesn't matter.
  583.  
  584. Next John wants to know if all ports are firewalled by that firewall. So 
  585. he does another probe:
  586.  
  587. --- 
  588. # hping -A -p 85 -c 1 -t 19 www.totallysecure.org
  589. HPING www.totallysecure.org (eth0 123.123.123.123): A set, 40 headers + 0 data bytes
  590. TTL 0 during transit from ip=123.123.123.1 name=UNKNOWN
  591.  
  592. --- www.totallysecure.org hping statistic ---
  593. 1 packets tramitted, 0 packets received, 100% packet loss
  594. round-trip min/avg/max = 0.0/0.0/0.0 ms
  595. #
  596. --- end ---
  597.  
  598. Nope, we receive an ICMP port unreachable atleast port 85 is not filtered
  599. at the same address as ICMP is filtered.
  600.  
  601. Now there are only two options: the packet is filtered at the gateway just 
  602. before the webserver, or on the webserver itself:
  603.  
  604. --- determining where port 85 is filtered  ---
  605.  
  606. # hping -A -p 85 -c 1 -t 20 www.totallysecure.org
  607. HPING www.totallysecure.org (eth0 123.123.123.123): A set, 40 headers + 0 data bytes
  608.  
  609. --- www.totallysecure.org hping statistic ---
  610. 1 packets tramitted, 0 packets received, 100% packet loss
  611. round-trip min/avg/max = 0.0/0.0/0.0 ms
  612. #
  613.  
  614. --- end ---
  615.  
  616. Port 85 is filtered at the gateway before the webserver.
  617. Let's see which address this gateway has:
  618.  
  619. --- resolving gateway address ---
  620.  
  621. # hping -S -p 80 -c 1 -t 20 www.totallysecure.org
  622. HPING www.totallysecure.org (eth0 123.123.123.123): S set, 40 headers + 0 data bytes
  623. TTL 0 during transit from ip=123.123.123.1 name=UNKNOWN
  624.  
  625. --- www.totallysecure.org hping statistic ---
  626. 1 packets tramitted, 0 packets received, 100% packet loss
  627. round-trip min/avg/max = 0.0/0.0/0.0 ms
  628.  
  629. #
  630.  
  631. --- end ---
  632.  
  633. As we already knew, it is 123.123.123.1 that is firewalling this port.
  634.  
  635. John continues his probing work and finds out the following:
  636.  
  637. 123.123.1.1 (hop 19) filters: ICMP, TCP port 31337
  638. 123.123.123.1 (hop 20) filters: All TCP ports except port 80
  639.  
  640. John considers that TotallySecure Inc. owns the whole 123.123.123.0 
  641. segment, and that 123.123.123.1 is their own firewall. 123.123.1.1 is 
  642. probably the gateway of their ISP (Internet Service Provider).
  643.  
  644. John draws the following 3D map:
  645.  
  646.   *******************
  647.   # 123.123.123.123 #
  648.   *******************
  649.   _________|_____________|_____________|_____________|_____________|__
  650.                            |
  651.                    *****************
  652.                    # 123.123.123.1 #
  653.                    *****************
  654.   ___________|_____________|_____________|_____________|______________
  655.                                    |
  656.                             ***************
  657.                             # 123.123.1.1 #
  658.                             ***************
  659.                                    |
  660.                                   ***
  661.                                ***   ***
  662.                            **** INTERNET ****
  663.                                ***   ***
  664.                                   ***
  665.  
  666. John believes that TotallySecure Inc.'s network must have a mailserver 
  667. that's in the 123.123.123.0 segment. So how could he verify this? Simple:
  668.  
  669. --- lookup mailserver ---
  670.  
  671. # host -t mx totallysecure.org
  672. totallysecure.org mail is handled by 100 relay1.bizznet.com.
  673. totallysecure.org mail is handled by 50 mail.totallysecure.org.
  674. #
  675.  
  676. --- end ---
  677.  
  678. Aha, two mail handlers, one appears to be the one of the ISP, and one 
  679. probably operated by totallysecure themselves.
  680.  
  681. # host relay1.bizznet.com
  682. relay1.bizznet.com has address 123.123.1.65
  683. # host mail.totallysecure.org
  684. mail.totallysecure has address 123.123.123.80
  685. #
  686.  
  687. John draws the new 3D map:
  688.  
  689.   *******************          ******************
  690.   # 123.123.123.123 #          # 123.123.123.80 #
  691.   *******************          ******************
  692.   _________|_____________|_____________|_____________|_____________|__
  693.                            |
  694.                    *****************           ****************
  695.                    # 123.123.123.1 #           # 123.123.1.65 #
  696.                    *****************           ****************
  697.   ___________|_____________|_____________|_____________|______________
  698.                                    |
  699.                             ***************
  700.                             # 123.123.1.1 #
  701.                             ***************
  702.                                    |
  703.                                   ***
  704.                                ***   ***
  705.                            **** INTERNET ****
  706.                                ***   ***
  707.                                   ***
  708.  
  709. The firewall only passes port 80 traffic if the destination is the 
  710. webserver, and port 25 only if the destination is the mailserver. Very 
  711. smart! John continues to fill in the above geographical map with this 
  712. information and the gathered information from the 2D mapping.
  713.  
  714. Note that the 3D mapping thing includes a technique called 'Firewalking' 
  715. discovered by Mike D. Schiffman and David E. Goldsmith. They also wrote a 
  716. program called 'Firewalk' to bring this technique to the public. You can 
  717. more information on it here:
  718. http://www.packetfactory.net/Projects/firewalk/
  719.  
  720. John continues to scan all 255 possible hosts behind the firewall, but 
  721. comes up with no new results.
  722.  
  723. 5. Using the gathered information
  724.  
  725. John knows that this packet filter is set up fairly restricted:
  726.  
  727. - John sees no possibity to compromise the firewall itself
  728. - John can't use no classic inbound backdoor when exploiting weaknesses in 
  729.   a system behind the firewall
  730. - No ICMP channel available
  731.  
  732. In later stages when John is able to compromise one of the servers behind 
  733. the firewall (either through active attack on the mailserver or attack on 
  734. the webserver), he won't be able to use a classical inbound backdoor.
  735.  
  736. To play it safe, John needs to trojan or patch either the mailserver 
  737. software or the webserver. Another way is to use a reversely connecting 
  738. backdoor, that connects to a local server on your system instead of the 
  739. reverse. But that would not be very smart, as the backdoor would require 
  740. to know the address of his attacking host, also outgoing traffic may be 
  741. restricted too.
  742.  
  743. A backdoor on the webserver could be a server-side script that can execute 
  744. things through a webinterface. Or a special module, or a real patch of the 
  745. webserver which can be controlled through specially crafted requests. 
  746. Otherwise, the mailserver needs to be patched.
  747.  
  748. He could also create an automated program which works like a worm that 
  749. compromises the whole network behind the firewall and leaks information 
  750. back to John, which would require John to guess what vulnerabilities 
  751. could be exploited behind the firewall.
  752.  
  753. 6. Final words
  754.  
  755. In this part you learned how to gain important information about the 
  756. target's network set-up as well as understanding how packet filters are 
  757. configured and how they sometimes can be bypassed.
  758.  
  759. These methods should be part of the information gathering stage discussed 
  760. in part 2, though there was somuch to tell that it deserves a seperate 
  761. part.
  762.  
  763. Please look out for new 'Hacking Unix' parts during the next couple of
  764. months.
  765.  
  766. detach (XT) [DuHo] 2002
  767.  
  768. Visit http://www.duho.org/ for updates or new parts of this tutorial every
  769. now and then.
  770.  
  771. -EOF-
  772. Size: 32768 bytes
  773. chars: 29428 
  774. words: 4556
  775. Lines: 767
  776.